// mapper/ReportMapper.java
package com.example.demo.mapper;

import com.example.demo.model.Report;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ReportMapper {
    @Insert("INSERT INTO report(torrent_id, reporter_id, reason, description, report_time, status) " +
            "VALUES(#{torrentId}, #{reporterId}, #{reason}, #{description}, #{reportTime}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertReport(Report report);

    @Select("SELECT * FROM report WHERE id = #{id}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "torrentId", column = "torrent_id"),
            @Result(property = "reporterId", column = "reporter_id"),
            @Result(property = "reason", column = "reason"),
            @Result(property = "description", column = "description"),
            @Result(property = "reportTime", column = "report_time"),
            @Result(property = "status", column = "status"),
            @Result(property = "adminId", column = "admin_id"),
            @Result(property = "processTime", column = "process_time"),
            @Result(property = "processResult", column = "process_result"),
            @Result(property = "actionTaken", column = "action_taken")
    })
    Report getReportById(Long id);

    @Select("SELECT * FROM report WHERE status = #{status} ORDER BY report_time DESC")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "torrentId", column = "torrent_id"),
            @Result(property = "reporterId", column = "reporter_id"),
            @Result(property = "reason", column = "reason"),
            @Result(property = "description", column = "description"),
            @Result(property = "reportTime", column = "report_time"),
            @Result(property = "status", column = "status"),
            @Result(property = "adminId", column = "admin_id"),
            @Result(property = "processTime", column = "process_time"),
            @Result(property = "processResult", column = "process_result"),
            @Result(property = "actionTaken", column = "action_taken")
    })
    List<Report> getReportsByStatus(Integer status);

    @Update("UPDATE report SET status = #{status}, admin_id = #{adminId}, " +
            "process_time = #{processTime}, process_result = #{processResult}, " +
            "action_taken = #{actionTaken} WHERE id = #{id}")
    int updateReport(Report report);

}